package com.guli.gulimall.search.controller;

import com.guli.common.utils.R;
import com.guli.common.vo.SkuEsModel;
import com.guli.gulimall.search.service.SearchService;
import com.guli.gulimall.search.vo.SearchParam;
import com.guli.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName SearchController
 * @Author Hao_YunKai
 * @Date 2022/1/7 21:33
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping(value = {"/","search.html"})
    public String search(SearchParam searchParam, Model model) throws Exception{
        SearchResult searchResult = searchService.search(searchParam);
        model.addAttribute("searchResult",searchResult);
        return "search";
    }

    @PostMapping("/up/product")
    @ResponseBody
    public R upProduct(@RequestBody List<SkuEsModel> list) throws IOException {
        return searchService.upAll(list);
    }
}
